package cn.edu.wfit.modules.learn.controller.coursemanagement;

import java.util.List;

import cn.edu.wfit.modules.learn.domain.WfitStuCourse;
import cn.edu.wfit.modules.learn.service.coursemangement.IWfitStuCourseService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;

import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 课程学生关联Controller
 * 
 * @author ruoyi
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/join")
public class WfitStuCourseController extends BaseController
{
    @Autowired
    private IWfitStuCourseService wfitStuCourseService;

    /**
     * 查询课程学生关联列表
     */
    @RequiresPermissions("system:course:list")
    @GetMapping("/list")
    public TableDataInfo list(WfitStuCourse wfitStuCourse)
    {
        startPage();
        List<WfitStuCourse> list = wfitStuCourseService.selectWfitStuCourseList(wfitStuCourse);
        return getDataTable(list);
    }

    /**
     * 导出课程学生关联列表
     */
    @RequiresPermissions("system:course:export")
    @Log(title = "课程学生关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfitStuCourse wfitStuCourse)
    {
        List<WfitStuCourse> list = wfitStuCourseService.selectWfitStuCourseList(wfitStuCourse);
        ExcelUtil<WfitStuCourse> util = new ExcelUtil<WfitStuCourse>(WfitStuCourse.class);
        util.exportExcel(response, list, "课程学生关联数据");
    }

    /**
     * 获取课程学生关联详细信息
     */
    @RequiresPermissions("system:course:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wfitStuCourseService.selectWfitStuCourseById(id));
    }

    /**
     * 新增课程学生关联
     */
    @RequiresPermissions("system:course:add")
    @Log(title = "课程学生关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfitStuCourse wfitStuCourse)
    {
        return toAjax(wfitStuCourseService.insertWfitStuCourse(wfitStuCourse));
    }

    /**
     * 修改课程学生关联
     */
    @RequiresPermissions("system:course:edit")
    @Log(title = "课程学生关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfitStuCourse wfitStuCourse)
    {
        return toAjax(wfitStuCourseService.updateWfitStuCourse(wfitStuCourse));
    }

    /**
     * 删除课程学生关联
     */
    @RequiresPermissions("system:course:remove")
    @Log(title = "课程学生关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wfitStuCourseService.deleteWfitStuCourseByIds(ids));
    }
}
